package yxy.game.pm2.active.command.limitexchange;

import yxy.cherry.game.base.message.MessageEmitterHandler;
import yxy.cherry.game.base.message.annotation.MessageSource;
import yxy.cherry.game.base.message.annotation.MessageType;
import yxy.game.pm2.Result;
import yxy.game.pm2.active.handle.Act_ConquestHandle;
import yxy.game.pm2.command.Command;
import yxy.game.pm2.message.ActiveMessage;

/** 限时兑换征战 关卡扫荡询问 */
@MessageType(proto = Command.ActLimitExchangeConquestSweepOnceAsk, classtype = ActiveMessage.ActLimitExchangeConquestSweepOnceAskRequest.class)
public class CMD_Active_限时兑换_ConquestSweepOnceAsk extends Command<ActiveMessage.ActLimitExchangeConquestSweepOnceAskRequest> {

	@Override
	public void execute(MessageSource messageSource, ActiveMessage.ActLimitExchangeConquestSweepOnceAskRequest request) {
		String playerCode = messageSource.getTag();

		Act_ConquestHandle conquestHandle = new Act_ConquestHandle();
		Result result = conquestHandle.sweepOnceAsk(playerCode);
		if (result.equals(Result.ConquestRewardUpper)) {
			ActiveMessage.ActLimitExchangeConquestSweepOnceAskResponse.Builder response = ActiveMessage.ActLimitExchangeConquestSweepOnceAskResponse.newBuilder();
			send(messageSource, response, result);
			return;
		}

		ActiveMessage.ActLimitExchangeConquestSweepOnceResponse.Builder response = ActiveMessage.ActLimitExchangeConquestSweepOnceResponse.newBuilder();

		try {
			result = new Act_ConquestHandle().sweepOnce_Act限时兑换(playerCode, response);
			send(messageSource, response, result);
		} catch (Exception e) {
			send(messageSource, response, Result.DataError);
		}
	}

	private void send(MessageSource messageSource, ActiveMessage.ActLimitExchangeConquestSweepOnceAskResponse.Builder response, Result result) {
		response.setResult(result.packResult());
		MessageEmitterHandler.getInstance().send(messageSource, response.build());
	}

	private void send(MessageSource messageSource, ActiveMessage.ActLimitExchangeConquestSweepOnceResponse.Builder response, Result result) {
		response.setResult(result.packResult());
		MessageEmitterHandler.getInstance().send(messageSource, response.build());
	}
}